<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>发送朋友圈</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/web/res/css/xadmin.css">
    <script src="/web/res/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/web/res/js/xadmin.js"></script>
</head>

<style type="text/css">
    .uploader-list {
        margin-left: -15px;
    }

    .uploader-list .info {
        position: relative;
        margin-top: -25px;
        background-color: black;
        color: white;
        filter: alpha(Opacity=80);
        -moz-opacity: 0.5;
        opacity: 0.5;
        width: 100px;
        height: 25px;
        text-align: center;
        display: none;
    }

    .uploader-list .handle {
        position: relative;
        background-color: black;
        color: white;
        filter: alpha(Opacity=80);
        -moz-opacity: 0.5;
        opacity: 0.5;
        width: 100px;
        text-align: right;
        height: 18px;
        margin-bottom: -18px;
        display: none;
    }

    .uploader-list .handle i {
        margin-right: 5px;
    }

    .uploader-list .handle i:hover {
        cursor: pointer;
    }

    .uploader-list .file-iteme {
        margin: 12px 0 0 15px;
        padding: 1px;
        float: left;
    }
</style>


<body style="background-color: white;">
<div class="layui-fluid" id="orderEdit">
    <form class="layui-form layui-form-pane" id="formsubmit" style="width: 500px;margin:20px auto"
          action="/app/dongtai/afterSendDongtai">
        <!--用户id 隐藏-->
        <div class="layui-form-item">
            <label class="layui-form-label">用户ID</label>
            <div class="layui-input-block">
                <input type="text" name="userId" required lay-verify="required" autocomplete="off"
                       class="layui-input"
                       readonly value="${(user.id?c)!''}"/>
            </div>
        </div>
        <!--登录名-->
        <div class="layui-form-item">
            <label class="layui-form-label">登录名</label>
            <div class="layui-input-block">
                <input type="text" name="loginname" required lay-verify="required" autocomplete="off"
                       class="layui-input"
                       readonly value="${(user.loginname)!''}"/>
            </div>
        </div>
        <!--图片-->
        <!--        <div class="layui-form-item">-->
        <!--            <div class="layui-upload">-->
        <!--                <label class="layui-form-label lable-text-center">图片</label>-->
        <!--                <div class="upload-list" id="uploadlist">-->
        <!--                    <div class="upload-img" id="uploadtemplate">+</div>-->
        <!--                </div>-->
        <!--            </div>-->
        <!--        </div>-->


        <div class="layui-upload">
                
            <button type="button" class="layui-btn" id="test2">多图片上传</button>
            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;width: 88%">
                    预览图：
                    
                <div class="layui-upload-list uploader-list" style="overflow: auto;" id="uploader-list">

                        
                </div>
            </blockquote>
        </div>

        <input type="hidden" id="image" name="image" lay-verify="required" autocomplete="off"
               class="layui-input"
               value=""/>

        <!--内容-->
        <div class="layui-form-item">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-block">
                <input type="text" name="message" required lay-verify="required" autocomplete="off" class="layui-input"
                       value=""/>
            </div>
        </div>

        <!--操作-->
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn layui-btn-radius" lay-submit lay-filter="save">&emsp;保存&emsp;
                </button>
                <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" onclick="xadmin.close()">
                    &emsp;返回&emsp;
                </button>
            </div>
        </div>


    </form>
</div>

<script>

    layui.use(['form', 'upload'], function () {
        let $ = layui.$;
        var form = layui.form;
        var upload = layui.upload;
        form.render();

        var str = '';

        upload.render({
            elem: '#test2'
            , url: '/app/dongtai/afterDongtaiUpOssImg'
            , multiple: true
            , before: function (obj) {
                // layer.msg('图片上传中...', {
                //     icon: 16,
                //     shade: 0.01,
                //     time: 0
                // })
            }
            , done: function (res) {
                layer.close(layer.msg());//关闭上传提示窗口
                //上传完毕
                $('#uploader-list').append(
                    '<div id="" class="file-iteme">' +
                    '<div class="handle"><i class="layui-icon layui-icon-delete"></i></div>' +
                    '<img style="width: 100px;height: 100px;" src=' + res.data.name + '>' +
                    '<input type="hidden"  id="imgpathhide" value="' + res.data.name + '"  class="layui-input"/>' +
                    '</div>'
                );
                str += res.data.name + ","
                $('#image').val(str);
            }
        });

        $(document).on("mouseenter mouseleave", ".file-iteme", function (event) {
            if (event.type === "mouseenter") {
                //鼠标悬浮
                $(this).children(".info").fadeIn("fast");
                $(this).children(".handle").fadeIn("fast");
            } else if (event.type === "mouseleave") {
                //鼠标离开
                $(this).children(".info").hide();
                $(this).children(".handle").hide();
            }
        });
        // 删除图片
        $(document).on("click", ".file-iteme .handle", function (event) {
            $(this).parent().remove();
        });


        // upload.render({
        //     elem: '#uploadtemplate',
        //     // auto: false,
        //     url: '/app/dongtai/afterDongtaiUpOssImg',
        //     accept: 'images',
        //     acceptMime: 'image/*',
        //     choose: function (obj) {
        //
        //     },
        //     done: function (res) {
        //         $('#uploadlist').prepend(
        //             '<div class="upload-imgBox">  <input type="hidden"  id="imgpathhide" value="' + res.data.name + '"  class="layui-input"/><div class="upload-cancel">x</div><img  src="' + res.data.name + '" class="upload-select-img"></div>');
        //         $(".upload-cancel").on("click", function (e) {
        //             $(this).parent().remove();
        //             if ($("input[id='imgpathhide']").length < 1) {
        //                 $('#uploadtemplate').show();
        //             }
        //         })
        //         if ($("input[id='imgpathhide']").length >= 1) {
        //             $('#uploadtemplate').hide();
        //         }
        //     }
        // });

        $.fn.extend({
            serializeObject: function () {
                var obj = {}; //声明一个对象
                $.each(this.serializeArray(), function (index, field) {
                    obj[field.name] = field.value; //通过变量，将属性值，属性一起放到对象中
                })
                return obj;
            }
        });
        form.on('submit(' + $("button[lay-submit]:eq(0)").attr("lay-filter") + ')', function (data) {

            layer.confirm('确认要保存吗？', function (index) {
                var loading = layer.load(0, {
                    shade: true
                });
                ajaxPost($, $("#formsubmit").attr("action"), $("#formsubmit").serializeObject(), function (data) {
                    layer.close(loading);
                    if (data.code == 0) {

                        layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                            xadmin.father_reload();
                        });
                    } else {
                        layer.close(loading);
                        layer.msg(data.msg, {icon: 2, time: 3000}, function () {

                        });
                    }
                });
            });
        });

    });


</script>

</body>

</html>